﻿//https://leetcode.cn/problems/merge-intervals/

lass Solution{
public:
    vector<vector<int>> merge(vector<vector<int>>&intervals)
    {
        //左端点排序
        sort(intervals.begin(),intervals.end());

        int left = intervals[0][0],right = intervals[0][1];
        vector<vector<int>> ret;

        for (int i = 1; i < intervals.size(); i++)
        {
            int a = intervals[i][0],b = intervals[i][1];
            //有重叠部分
            if (right >= a)
            {
                right = max(right,b);
            }
            //无重叠部分
            else
            {
                ret.push_back({left,right});
                left = a;
                right = b;
            }

        }
        ret.push_back({left,right});
        return ret;

    }
};